<template>
  <div class="container-big">
    <ul class="tablist">
      <li :class="active==index?`active`:``" @click="getAcitve(index)" v-for="(item,index) in tablist">{{ item.label }}</li>
    </ul>
    <div class="content-big">
      <div class="content-left">
        <div class="left-title">分组</div>
        <div class="flex">
          <div class="search">
            <el-input v-model="queryParams.userName1" size="small" placeholder="标签组" clearable/>
            <el-button icon="el-icon-search" size="small" @click="handleQuery"></el-button>
          </div>
        </div>
        <ul class="treeList">
          <li v-for="(item,index) in treeList" @click="isOpenNode(index)">
              <div v-show="item.showChildren">
                <dl v-if="item.children && item.children.length>0" v-for="(sitem,sindex) in item.children">
                  <dd :class="treeActive==index && smallActive==sindex?`treeActive`:``" @click.stop="getTreeActive(index,sindex)"><i class="el-icon-caret-right" style="opacity: 0"></i>{{ sitem.label }}
                  </dd>
                </dl>
              </div>


          </li>
        </ul>
      </div>
      <div class="content-right">
        <div class="echart-big">
          <div class="left-echart">
            <div class="title">标签占比</div>
             <div id="echart-pie" style="width: 100%; height:calc(100% - 50px); border: 1px solid #eee"></div>
          </div>
          <div class="right-echart">
            <div class="title">对比昨日</div>
            <div id="echart-bar" style="width: 100%; height:calc(100% - 50px); border: 1px solid #eee"></div>
          </div>
        </div>
        <div class="data-table">
          <div class="title">分日数据</div>
          <el-date-picker
            size="small"
            v-model="dateRange"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
          <el-table
            :data="recordDataList"
            ref="companylabelList"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              :label="item.label"
              align="left"
              v-for="(item, index) in recordTableColumns"
              :key="index"
              :prop="item.key"
              :min-width="item.minWidth ? item.minWidth : ``"
              :fixed="item.fixed ? item.fixed : false"
              :show-overflow-tooltip="true"
            >
              <!--用于表格自定义-->
              <template slot-scope="scope">
                <div v-if="item.key=='name'">
                  <div class="userInfo">
                    <img src="@/assets/images/profile.jpg"/>
                    <div class="name">小城红</div>
                    <div class="label">@志新</div>
                  </div>
                </div>
                <div class="label-list" v-else-if="item.key=='label'">
                  <label>自动打上：</label>
                  <span>未入VIP群</span>
                  <span>持续7天未发言</span>
                  <span>1000</span>
                </div>
                <div v-else-if="item.key=='code'">
                  <div class="userInfo">
                    <img src="@/assets/images/profile.jpg"/>
                    <div class="name">小城红</div>
                    <div class="label">@志新</div>
                  </div>
                </div>
                <div v-else>{{ scope.row[item.key] }}</div>
              </template>
            </el-table-column>

          </el-table>
        </div>

      </div>
    </div>
  </div>
</template>
<script>
import {listUser} from "@/api/system/user";
import * as echarts from 'echarts';
export default {
  name: "dataBoardEchart",
  data(){
    return{
      active:3,
      treeActive:3,
      smallActive:3,
      dateRange:[],
      tablist: [
      //  {value: 1, label: '行为标签',},
        // {value: 2, label: '生命周期标签',},
         {value: 3, label: '客户价值标签',},
        // {value: 4, label: '时间进程标签',},
        // {value: 5, label: '自定义标签',},
      ],
      treeList: [
        {
          value: 1, label: '社群行为',
          showChildren: true,
          children: [
            {value: 3, label: '未入常规群',},
            {value: 4, label: '已入常规群',},
          ]
        },
        {
          value: 2, label: '私聊活跃度',
          showChildren: false,
          children: [
            {value: 5, label: '新好友一小时未发言',},
            {value: 6, label: '持续三天未发言',},
          ]
        },
      ],
      recordDataList: [],
      recordHeight: 600,
      recordTableColumns: [
        {key: 'name', label: `日期`, visible: true, minWidth: 150, fixed: true},
        {key: 'label', label: `<1000`, visible: true, minWidth: 150, fixed: false},
        {key: 'code', label: `1000-5000`, visible: true, minWidth: 150, fixed: false},
      ],
      // 查询参数
      queryParams: {
        userName1: null,


      },
    }
  },
  mounted(){
    this.$nextTick(()=>{
      this.getPie();//饼图
      this.getBar();//柱状体
    })

  },
  methods:{
    getAcitve(index) {
      this.active = index;
    },
    getTreeActive(index, sindex) {
      this.treeActive = index;
      this.smallActive = sindex;
    },
    isOpenNode(index) {
      this.treeList[index].showChildren = !this.treeList[index].showChildren;
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.tableDataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getBar(){

      var chartDom = document.getElementById('echart-bar');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            crossStyle: {
              color: '#999'
            }
          }
        },
        toolbox: {
          feature: {
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ['line', 'bar'] },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        legend: {
          data: ['Evaporation', 'Precipitation', 'Temperature']
        },
        xAxis: [
          {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            axisPointer: {
              type: 'shadow'
            }
          }
        ],
        yAxis: [
          {
            type: 'value',
            name: 'Precipitation',
            min: 0,
            max: 250,
            interval: 50,
            axisLabel: {
              formatter: '{value} ml'
            }
          },
          {
            type: 'value',
            name: 'Temperature',
            min: 0,
            max: 25,
            interval: 5,
            axisLabel: {
              formatter: '{value} °C'
            }
          }
        ],
        series: [
          {
            name: 'Evaporation',
            type: 'bar',
            tooltip: {
              valueFormatter: function (value) {
                return value + ' ml';
              }
            },
            data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
          },
          {
            name: 'Precipitation',
            type: 'bar',
            tooltip: {
              valueFormatter: function (value) {
                return value + ' ml';
              }
            },
            data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
          },
        ]
      };

      option && myChart.setOption(option);

    },
    getPie(){
      var chartDom = document.getElementById('echart-pie');
      var myChart = echarts.init(chartDom);
     let option = {
        // title: {
        //   text: 'Referer of a Website',
        //   subtext: 'Fake Data',
        //   left: 'center'
        // },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'right',
          top:'middle',
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: '50%',
            data: [
              { value: 1048, name: '1000' },
              { value: 735, name: '1000-5000' },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };

      option && myChart.setOption(option);
    },
  },
}
</script>

<style scoped lang="scss">
.tablist {
  display: flex;
  justify-items: center;
  border-left: none;
  border-radius: 4px 0 0 4px;
  position: relative;
  margin: 20px 0px 0px 0px;
  align-items: center;

  &:after {
    content: '';
    position: absolute;
    left: -40px;
    right: -40px;
    bottom: 0px;

  }

  li {
    margin: 0;
    padding: 8px 16px;
    background: #fafafa;
    border: 1px solid #e9e9e9;
    transition: all .3s cubic-bezier(.645, .045, .355, 1);
    list-style: none;
    font-size: 14px;
    margin: 0px 5px;
    cursor: pointer;

    &.active {
      border-color: #fff;
      color: #3070ff;
      background: #fff;
    }
  }
}
.left-title {
  font-size: 14px;
  font-weight: bold;
  background: #fff;
  padding-top: 16px;
  padding-bottom: 12px;

}
.container-big{
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  height: calc(100vh - 80px);
  margin: 12px;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
}
.search {
  display: flex;

  ::v-deep.el-input__inner {
    border-right: none !important;
    border-radius: 4px 0px 0px 0px;
  }

  ::v-deep .el-button--default {
    border-radius: 0px 4px 4px 0px;
    padding: 0px 10px;
  }
}
.treeList {
  display: flex;
  color: rgba(0, 0, 0, .85) !important;
  width: 100%;
  margin-top: 10px;
  font-size: 14px;
  flex-direction: column;

  li {
    list-style: none;
    width: 100%;

    .title {
      line-height: 20px;
      padding: 5px 0px;
      display: flex;
      justify-content: space-between;
      margin: 5px;
      cursor: pointer;

      i {
        padding-right: 5px;
      }
    }

    dl {
      padding: 0px;
      margin: 0px;

      dd {
        padding: 0px;
        margin: 0px;
        line-height: 20px;
        padding: 5px 0px;
        margin: 5px 0px;
        cursor: pointer;
        padding-right: 60px;
        position: relative;

        .number {
          position: absolute;
          right: 10px;
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: center;
          top: 0;
          color: rgba(0, 0, 0, .45);
        }

        i {
          padding-right: 5px;
        }

        &.treeActive {
          background: #ebf2ff !important;
          border-radius: 4px;
        }

      }
    }
  }
}
.content-big {
  height: calc(100vh - 180px);
  overflow-y: auto;
  background: #fff;
  display: flex;

  .content-left {
    width: 260px;
    border-right: 1px solid #eee;
    height: 100%;
    padding: 0 16px 16px;
    overflow-y: auto;


  }

  .content-right {
    flex: 1;
    padding:0px 15px;
  }
}

.echart-big {
  display: flex;
  height:336px;
  .left-echart {
    width: 35%;
    margin-right: 10px;

  }
  .right-echart {
    flex: 1;

  }
}
.title {
  font-size: 14px;
  font-weight: 600;
  color: rgba(0, 0, 0, .85);
  height: 50px;
  align-items: center;
  display: flex;
}
.el-table {
  margin-top: 10px;
}
</style>
